var roomid = 0;
var euid = null;
var roomName = '';
var currentPage = 1;
$(document).ready(function() {
	initRoomInfo();
	roomCount();
	roomPduList();
	doorOpeningTrendBySevenDay();
	showRoom();
	openDoorList();
	warnList();
	lastLockInfo();
	openLock();
	initForm();
	initVedio();
})

function initForm() {
	layui.use('form', function() {
        var form = layui.form;
        //监听提交
        form.on('select(pduSelectFilter)', function(data) {
            historyCharts(data.value);
        });
        
	});
}

function initVedio() {
	Ajax("/room/node/list_url?id="+roomid, initVedioSelectBack);
    function initVedioSelectBack(result){
    	$('.main-right-monitor-nav').empty();
        if (result.status == 200) {
        	var list = result.result;
			if (list != null && list != '' && list != 'undefined') {
				let div = '';
				for (var i=0; i<list.length; i++) {
					let res = list[i];
					if (i==0) {
						div = `<div class="room-monitor selected" data-url="${res.url}"><span>${res.name}</span></div>`;
						if (null != res.url && res.url != '' && res.url != '#') {
					    	 showVedio(res.url);
					    } else {
					    	$('.main-right-monitor-body').append(`<img src="../static/img/images/demo.png">`);
					    }
					} else {
						div = `<div class="room-monitor" data-url="${res.url}"><span>${res.name}</span></div>`;;
					}
					
					$('.main-right-monitor-nav').append(div);
				}
				
				$('.room-monitor').click(function(e) {
				    $(e.currentTarget).addClass('selected').siblings().removeClass('selected');
				    let url = $('.room-monitor.selected')[0].dataset.url;
				    if (null != url && url != '' && url != '#') {
				    	myPlayer.dispose();
				    	showVedio(url);
				    } else {
				    	$('.main-right-monitor-body').empty();
				    	$('.main-right-monitor-body').append(`<img src="../static/img/images/demo.png">`);
				    }

				});
			}
        }
    }
}

var myPlayer;
function showVedio(url){
	$('.main-right-monitor-body').empty();
	let str = `
	<video id="room-video" class="video-js" controls muted autoplay="autoplay">
        <source src="${url}" type="application/x-mpegURL">
    </video>
	`;
	$('.main-right-monitor-body').append(str);
	myPlayer = videojs('room-video');
    videojs("room-video").ready(function(){
        myPlayer = this;
        myPlayer.play();
    });
}

function roomCount() {
	var url = "/room/statistics?id="+roomid;
	Ajax(url, roomCountBack);
    function roomCountBack(result){
        if (result.status == 200) {
        	var data = result.result;
        	if (null != data && data != 'null') {
        		$('.roomRackNum').html(data.rackNumber);
        		$('.roomPduTotal').html(data.total);
        		$('.roomPduOpen').html(data.opening);
        		$('.roomPduClose').html(data.closed);
        	}
        }
    }
}

function roomPduList(pageNum, pageSize) {
	if (!pageNum) {
        pageNum = 1;
    }
    if (!pageSize) {
        pageSize = 12;
    }
    
    $('.main-left-pdulist-list').html('');
    Ajax('/room/pdu/list?pageSize='+pageSize+'&pageNum='+pageNum+'&id='+roomid, roomPduListBack);
    function roomPduListBack(result){
        if (result.status == 200) {
        	let list = result.result.data;
        	let total = result.result.total;
        	if (0 == total % pageSize) {
                totalPage = parseInt(total / pageSize);
                if (totalPage == 0) totalPage = 1;
            } else {
                totalPage = parseInt(total / pageSize) + 1;
            }
    		if (list != null && list != 'null') {
    		    for (var i=0;i<list.length;i++) {
    		    	let status = list[i].status;
    		    	let deviceName = list[i].deviceName;
                	let icon;
                	if (status == 0) {
                		icon = "../static/img/images/close.png";
                	} else if (status == 1) {
                		icon = "../static/img/images/open.png";
                	} else if (status == null) {
                		icon = "../static/img/images/offline-pdu.png";
                	}
                	let divstr = `
                	    <div class="main-left-pdulist-list-item pdulist-open">
                            <img src=${icon}>
                            <div>${deviceName}</div>
                        </div>
                	`;
                	$('.main-left-pdulist-list').append(divstr);
    		    }
    		}
        }
        
        $('.main-left-pdulist-list').fadeIn();
        $('#pagination').fadeIn();
        $("#pagination").paginations({
            currentPage: currentPage,
            totalPage: totalPage,
            callback: function(current) {
                currentPage = current;
                roomPduList(current, pageSize);
            }
        });
    }
}

/*近7日门禁开启趋势 */
function doorOpeningTrendBySevenDay() {
	var trend = [];
	var days = [];
	
	var url = "/room/lock/countsevendays?id="+roomid;
	Ajax(url, getDoorOpenTrendBack);
    function getDoorOpenTrendBack(result){
        if (result.status == 200) {
        	var data = result.result;
            $.each(data, function(index, item) {
            	days.push(index.substr(5));
            	trend.push(item);
            });
            
            var option = {
		        color: '#fff',
		        grid: {
		            top: '20%',
		            left: '3%',
		            right: '5%',
		            bottom: '7%',
		            containLabel: true
		        },
		        tooltip: {
		            trigger: 'axis'
		        },
		        xAxis: [{
		            type: 'category',
		            boundaryGap: false,
		            data: days,
		            axisTick: {
		                alignWithLabel: true
		            },
		            axisTick: {
		                alignWithLabel: true
		            },
		            axisLine: {
		                show: true,
		                lineStyle: {
		                    color: '#54A1F1',
		                    width: 2
		                }
		            },
		            axisLabel: {
		                color: 'white',
		                fontSize: '10'
		            },
		            axisTick: {
		                show: false
		            },
		        }],
		        yAxis: [{
		            type: 'value',
		            minInterval: 1,
		            axisLine: {
		                show: true,
		                lineStyle: {
		                    color: '#54A1F1',
		                    width: 2
		                }
		            },
		            splitLine: {
		                lineStyle: {
		                    color: '#112B6F'
		                }
		            },
		            axisLabel: {
		                color: 'white',
		                fontSize: '10',
		                formatter:'{value}次'
		            },
		            axisTick: {
		                show: false
		            },
		        }],
		        series: [{
		            data: trend,
		            type: 'line',
		            smooth: true,
		            areaStyle: {
		                color: 'rgba(84, 161, 241, 1)'
		            },
		        }]
		    };
		    
		    var myChart = echarts.init(document.getElementById('main-mid-chart-trend'));
            myChart.setOption(option);
        }
    }
}

function showRoom() {
	Ajax("/room/pdu/list_rack?id="+roomid, showRoomBack);
    function showRoomBack(result){
        if (result.status == 200) {
        	var data = result.result;
        	if (data != null && data != 'null') {
        		let id = 1;
            	if (roomid == 2) {
            		id = 1;
            	} else if (roomid == 9) {
            		id = 3;
            	} else if (roomid == 3) {
            		id = 4;
            	} else if (roomid == 8) {
            		id = 1;
            	}
        		$('.main-mid-map').empty();
        		$('.main-mid-map').attr('id','main-mid-room'+id);
        		var title = `<div id="image-door" class="image-door"></div>
                             <img src="../static/img/images/icon14.png">
                             <img src="../static/img/images/icon15.png">`;
                $('.main-mid-map').append(title);
                $.each(data, function(index, item) {
	            	var divstr = `<div class="main-mid-map-device" id="room${id}-image-device${index+1}" rackNum="${item}"></div>`;
        			$('.main-mid-map').append(divstr);
	            });
        	}
        	
        	/*点击图中设备弹出事件*/
		    $('.main-mid-map-device').click(function() {
		        $(this).addClass('visited').siblings().removeClass('visited');
		        let rackNum = $(this).attr("rackNum");
		        showRackPduStatus(rackNum);
		        $('.pdu-msg').show(function(){
		        	$('.history-search').click(function() {
					    loadTableData(rackNum);
					});
					initPduSelect(rackNum);
		        });
		    })
		    /*关闭设备弹窗*/
		    $('.pdu-msg-close').click(function() {
		        $('.pdu-msg').hide();
		        $('.main-mid-map-device').removeClass('visited');
		    })
		    
		    /*打开门禁信息*/
			$('.image-door').click(function() {
			    $('.door-msg').show(function(){
			    	loadDoorOpenData();
			    });
			});
			
			/*关闭门禁信息*/
			$('.door-msg-close').click(function() {
			    $('.door-msg').hide();
			});
			
			/*点击门禁详情切换事件*/
		    $('.door-msg-tool-nav').click(function() {
		        $(this).addClass('selected').siblings().removeClass('selected');
		        if ($(this).context.dataset.id == 1) {
		            $('.door-msg-body-list.openrecord').show().siblings().hide();
		            $('.door-msg-body-list.warnrecord').hide();
		            $('.door-msg-body-list.statusrecord').hide();
		            $('.door-msg-body-list.remoterecord').hide();
		            loadDoorOpenData();
		        } else if ($(this).context.dataset.id == 2) {
		            $('.door-msg-body-list.warnrecord').show().siblings().hide();
		            $('.door-msg-body-list.openrecord').hide();
		            $('.door-msg-body-list.statusrecord').hide();
		            $('.door-msg-body-list.remoterecord').hide();
		            loadDoorWarnData();
		        } else if ($(this).context.dataset.id == 3) {
		        	$('.door-msg-body-list.statusrecord').show().siblings().hide();
		        	$('.door-msg-body-list.openrecord').hide();
		        	$('.door-msg-body-list.warnrecord').hide();
		        	$('.door-msg-body-list.remoterecord').hide();
		        	loadDoorStatusData();
		        } else if ($(this).context.dataset.id == 4) {
		        	$('.door-msg-body-list.remoterecord').show().siblings().hide();
		        	$('.door-msg-body-list.statusrecord').hide();
		        	$('.door-msg-body-list.openrecord').hide();
		        	$('.door-msg-body-list.warnrecord').hide();
		        	loadDoorRemoteData();
		        }
		    })
        	
        	$('.main-mid-map').show();
        }
    }
}

function openDoorList() {
	Ajax("/room/door/list?pageNum=1&pageSize=4&id="+roomid, openDoorListBack);
    function openDoorListBack(result){
        if (result.status == 200) {
        	var data = result.result.data;
        	if (data != null && data != 'null') {
        		$('.main-mid-chart-record-table').empty();
        		var title = `<div class="main-mid-chart-record-item">
                                <div style="flex:2">姓名</div>
                                <div style="flex:3">时间</div>
                                <div style="flex:2">开门类型</div>
                            </div>`;
                $('.main-mid-chart-record-table').append(title);
        		for (var i=0; i<data.length; i++) {
        			var info = data[i];
        			var divstr = `<div class="main-mid-chart-record-item">
                                <div style="flex:2">${info.chargePerson}</div>
                                <div style="flex:3">${info.passTime}</div>
                                <div style="flex:2">${info.passstatusname}</div>
                            </div>`;
        			$('.main-mid-chart-record-table').append(divstr);
        		}
        	}
        }
    }
}

function warnList() {
	Ajax("/room/alarm/list?pageNum=1&pageSize=5&id="+roomid, warnListBack);
    function warnListBack(result){
        if (result.status == 200) {
        	var data = result.result.data;
        	if (data != null && data != 'null') {
        		$('.main-right-alarm-table').empty();
        		var title = `<div class="main-right-alarm-item">
	                            <div style="flex:2">名称</div>
	                            <div style="flex:3">时间</div>
	                            <div style="flex:2">状态</div>
	                        </div>`;
                $('.main-right-alarm-table').append(title);
        		for (var i=0; i<data.length; i++) {
        			var info = data[i];
        			var time = info.eventTime;
        			if (null != time && time != '') {
        				time = time.substring(5,16);
        			}
        			var divstr = `<div class="main-mid-chart-record-item">
                                <div style="flex:2">${info.deviceName}</div>
                                <div style="flex:3">${time}</div>
                                <div style="flex:2">${info.eventStatus}</div>
                            </div>`;
        			$('.main-right-alarm-table').append(divstr);
        		}
        	}
        }
    }
}

function lastLockInfo() {
	Ajax("/room/lock/last?id="+roomid, lockInfoBack);
    function lockInfoBack(result){
        if (result.status == 200) {
        	var data = result.result;
        	if (data != null && data != 'null') {
        		$('.lastOpenDoorTime').html(data.batSigUpdateTime);
        		if (euid == null) {
        			euid = data.euid;
        		}
        	}
        }
    }
}

function openLock() {
    $('.main-right-status-button').click(function() {
    	if (euid == null) {
    		layer.msg("未找到门锁，请确定已经配置门锁设备信息");
    	} else {
    		var url = '/room/lock/start?euid='+euid;
		    layer.confirm('确定请求远程开门吗?', {
		        btn: ['确定', '取消']
		    }, function(isConfirm) {
		        Ajax(url, openLockBack);
		        function openLockBack(result){
		            let resultType = result.resultType;
		            let resultInfo = result.resultInfo;
		            layer.msg("请求已发送，请等待！");
		        }
		    });
    	}
    })
}

function showRackPduStatus(rackNum) {
	$('.pdu-msg-right').html('');
	$('.pdu-msg-right').css('overflow-y', 'visible');
    layui.use('flow', function() {
        var $ = layui.jquery;
        var flow = layui.flow;
        flow.load({
            elem: '.pdu-msg-right',
            scrollElem: '.pdu-msg-right',
            done: function(page, next) {
                var list = [];
                Ajax('/room/pdu/list_status?pageSize=3&pageNum='+page+'&id='+roomid+'&rackNum='+rackNum, showRackPduStatusBack);
			    function showRackPduStatusBack(result){
			        if (result.status == 200) {
			        	let data = result.result.data;
                		if (data != null && data != 'null') {
                			let total = result.result.total;
		                    let pages = Math.ceil(total/3);
		                    if (page > 1) {
		                        $('.pdu-msg-right').css('overflow-y', 'scroll');
		                    }
		                    layui.each(data, function(index, item) {
		                    	let divstr = `
		                    	    <div class="pdu-msg-right-title">${item.deviceName}</div>
			                        <div class="pdu-msg-right-item">
			                            <div>电压：${item.electricVoltage} V</div>
			                            <div>电流：${item.electricCurrent} A</div>
			                            <div>温度：${item.temperature} °C</div>
			                            <div>上报时间：${item.time}</div>
			                            <div>状态：${item.status}</div>
			                        </div>
		                    	`;
		                        list.push(divstr);
		                    });
		                    next(list.join(''), page < pages);
                		}
			        }
			    }
            }
        });
    });
    
    /*pdu历史弹出事件*/
	$('.pdu-msg-more').click(function() {
	    $('.main').hide(function() {
	        $('.pdu-history').show(function() {
	            loadTableData(rackNum);
	            let deviceId = $('#pdu-select').val();
				historyCharts(deviceId);
	        });
	    });
	})
	/*pdu历史关闭事件*/
	$('.pdu-history-reback').click(function() {
	    $('.pdu-history').hide(function() {
	        $('.main').show();
	    });
	})
}

function initPduSelect(rackNum) {
	Ajax("/room/node/list?id="+roomid+"&rackNum="+rackNum, initPduSelectBack);
    function initPduSelectBack(result){
    	$('#pdu-select').empty();
        if (result.status == 200) {
        	var list = result.result;
			if (list != null && list != '' && list != 'undefined') {
				var option = '';
				for (var i=0; i<list.length; i++) {
					option = option + '<option value="' + list[i].deviceId + '">' + list[i].deviceName + '</option>';
				}
				
				$('#pdu-select').append(option);
			}
        }
        renderForm();
    }
}

function loadTableData(rackNum) {
	let searchDeviceName = $('.searchDeviceName').val();
	let searchDeviceCode = $('.searchDeviceCode').val();
    let url = '/room/pdu/list_history';
    layui.use('table', function() {
        var table = layui.table;

        //第一个实例
        table.render({
            title: '',
            text: {
                none: '暂无数据'
            },
            elem: '#pdu-history-body-left-table',
            skin: 'nob',
            url: ajaxPrefix() + url,
            headers: { SessionId: localStorage.getItem('sessionId') },
            where: {
                pageSize: 10,
                id: roomid,
                rackNum: rackNum,
                euid: searchDeviceCode,
                deviceName: searchDeviceName
            },
            parseData: function(res) { //res 即为原始返回的数据
                return {
                    "code": res.status == 200 ? 0 : 1, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.result.total, //解析数据长度
                    "data": res.result.data //解析数据列表
                };
            },
            request: {
                pageName: 'pageNum', //页码的参数名称，默认：page,
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            page: { limit: 10, } //开启分页
            ,
            cols: [
                [ //表头
                    { field: 'deviceName', title: '设备名称', align: 'center',width:'10%' },
                    { field: 'euid', title: '设备编号', align: 'center',width:'10%' },
                    { field: 'electricVoltage', title: '电压（V）', align: 'center',width:'10%' },
                    { field: 'electricCurrent', title: '电流（A）', align: 'center',width:'10%'},
                    { field: 'temperature', title: '温度（℃）', align: 'center',width:'10%' },
                    { field: 'electricApparentEnergy', title: '视在电能（KWh）', align: 'center',width:'10%' },
                    { field: 'electricApparentPower', title: '视在功率（W）', align: 'center',width:'10%' },
                    { field: 'voltage', title: '电池电压（mV）', align: 'center',width:'10%' },
                    { field: 'status', title: '状态', align: 'center',width:'10%' },
                    { field: 'time', title: '上报时间', align: 'center',width:'10%' }
                ]
            ]
        });
    });
}

/*历史折线图*/
function historyCharts(deviceId) {
	var voltageTime = [];
	var voltage = [];
	
	Ajax("/room/pdu/voltage_trend?id="+roomid+"&deviceId="+deviceId, voltageChartBack);
    function voltageChartBack(result){
        if (result.status == 200) {
        	var data = result.result;
        	if (data != null && data != 'null') {
        		$.each(data, function(index, item) {
        			let time = item.time;
	            	voltageTime.push(time.substring(5));
	            	voltage.push(item.electricVoltage);
	            });
        	}
        	
        	/*电压*/
		    var option1 = {
		        color: ['#C5932B', '#0DF5F5', '#7067FF'],
		        grid: {
		            top: '23%',
		            left: '5%',
		            right: '10%',
		            bottom: '10%',
		            containLabel: true
		        },
		        tooltip: {
		            trigger: 'axis'
		        },
		        xAxis: [{
		            type: 'category',
		            boundaryGap: false,
		            data: voltageTime,
		            axisTick: {
		                alignWithLabel: true
		            },
		            axisTick: {
		                alignWithLabel: true
		            },
		            axisLine: {
		                show: true,
		                lineStyle: {
		                    color: '#54A1F1',
		                    width: 2
		                }
		            },
		            axisLabel: {
		                color: '#0999FC',
		                fontSize: '10'
		            },
		            axisTick: {
		                show: false
		            },
		        }],
		        yAxis: [{
		            type: 'value',
		            minInterval: 1,
		            axisLine: {
		                show: true,
		                lineStyle: {
		                    color: '#54A1F1',
		                    width: 2
		                }
		            },
		            splitLine: {
		                lineStyle: {
		                    color: '#112B6F'
		                }
		            },
		            axisLabel: {
		                color: 'white',
		                fontSize: '10',
		                formatter: '{value}V'
		            },
		            axisTick: {
		                show: false
		            },
		        }],
		        series: [{
		            data: voltage,
		            type: 'line',
		            smooth: true,
		        }]
		    };
		    var myChart1 = echarts.init(document.getElementById('pdu-voltage-chart'));
		    myChart1.setOption(option1);
        }
    }
    
    var currentTime = [];
    var current = [];
    Ajax("/room/pdu/current_trend?id="+roomid+"&deviceId="+deviceId, currentChartBack);
    function currentChartBack(result){
        if (result.status == 200) {
        	var data = result.result;
        	if (data != null && data != 'null') {
        		$.each(data, function(index, item) {
        			let time = item.time;
	            	currentTime.push(time.substring(5));
	            	current.push(item.electricCurrent);
	            });
        	}
        	
        	/*电流*/
		    var option2 = {
		        color: ['#C5932B', '#0DF5F5', '#7067FF'],
		        grid: {
		            top: '23%',
		            left: '5%',
		            right: '10%',
		            bottom: '10%',
		            containLabel: true
		        },
		        tooltip: {
		            trigger: 'axis'
		        },
		        xAxis: [{
		            type: 'category',
		            boundaryGap: false,
		            data: currentTime,
		            axisTick: {
		                alignWithLabel: true
		            },
		            axisTick: {
		                alignWithLabel: true
		            },
		            axisLine: {
		                show: true,
		                lineStyle: {
		                    color: '#54A1F1',
		                    width: 2
		                }
		            },
		            axisLabel: {
		                color: '#0999FC',
		                fontSize: '10'
		            },
		            axisTick: {
		                show: false
		            },
		        }],
		        yAxis: [{
		            type: 'value',
		            minInterval: 1,
		            axisLine: {
		                show: true,
		                lineStyle: {
		                    color: '#54A1F1',
		                    width: 2
		                }
		            },
		            splitLine: {
		                lineStyle: {
		                    color: '#112B6F'
		                }
		            },
		            axisLabel: {
		                color: 'white',
		                fontSize: '10',
		                formatter: '{value}A'
		            },
		            axisTick: {
		                show: false
		            },
		        }],
		        series: [{
		            data: current,
		            type: 'line',
		            smooth: true,
		        }]
		    };
		    var myChart2 = echarts.init(document.getElementById('pdu-current-chart'));
		    myChart2.setOption(option2);
        }
    }
    
    var temperatureTime = [];
    var temperature = [];
    Ajax("/room/pdu/temperature_trend?id="+roomid+"&deviceId="+deviceId, temperatureChartBack);
    function temperatureChartBack(result){
        if (result.status == 200) {
        	var data = result.result;
        	if (data != null && data != 'null') {
        		$.each(data, function(index, item) {
        			let time = item.time;
	            	temperatureTime.push(time.substring(5));
	            	temperature.push(item.temperature);
	            });
        	}
        	
        	/*温度*/
		    var option3 = {
		        color: ['#C5932B', '#0DF5F5', '#7067FF'],
		        grid: {
		            top: '23%',
		            left: '5%',
		            right: '10%',
		            bottom: '10%',
		            containLabel: true
		        },
		        tooltip: {
		            trigger: 'axis'
		        },
		        xAxis: [{
		            type: 'category',
		            boundaryGap: false,
		            data: temperatureTime,
		            axisTick: {
		                alignWithLabel: true
		            },
		            axisTick: {
		                alignWithLabel: true
		            },
		            axisLine: {
		                show: true,
		                lineStyle: {
		                    color: '#54A1F1',
		                    width: 2
		                }
		            },
		            axisLabel: {
		                color: '#0999FC',
		                fontSize: '10'
		            },
		            axisTick: {
		                show: false
		            },
		        }],
		        yAxis: [{
		            type: 'value',
		            minInterval: 1,
		            axisLine: {
		                show: true,
		                lineStyle: {
		                    color: '#54A1F1',
		                    width: 2
		                }
		            },
		            splitLine: {
		                lineStyle: {
		                    color: '#112B6F'
		                }
		            },
		            axisLabel: {
		                color: 'white',
		                fontSize: '10',
		                formatter: '{value}℃'
		            },
		            axisTick: {
		                show: false
		            },
		        }],
		        series: [{
		            data: temperature,
		            type: 'line',
		            smooth: true,
		        }]
		    };
		    var myChart3 = echarts.init(document.getElementById('pdu-temperature-chart'));
		    myChart3.setOption(option3);
        }
    }
    
}

function loadDoorOpenData() {
	$('.door-msg-body-list.openrecord>div:nth-child(1)').nextAll().remove();
	$('.door-msg-body-list.openrecord').css('overflow-y', 'visible');
    layui.use('flow', function() {
        var $ = layui.jquery;
        var flow = layui.flow;
        flow.load({
            elem: '.door-msg-body-list.openrecord',
            scrollElem: '.door-msg-body-list.openrecord',
            done: function(page, next) {
                var list = [];
                Ajax('/room/door/list?pageSize=10&pageNum='+page+'&id='+roomid, loadDoorOpenDataBack);
			    function loadDoorOpenDataBack(result){
			        if (result.status == 200) {
			        	let data = result.result.data;
                		if (data != null && data != 'null') {
                			let total = result.result.total;
		                    let pages = Math.ceil(total/10);
		                    if (page > 1) {
		                        $('.door-msg-body-list.openrecord').css('overflow-y', 'scroll');
		                    }
		                    layui.each(data, function(index, item) {
		                    	let divstr = `
		                    	    <div>
		                                <div style="flex:1">${item.chargePerson}</div>
		                                <div style="flex:2">${item.passTime}</div>
		                                <div style="flex:1">${item.passstatusname}</div>
		                            </div>
		                    	`;
		                        list.push(divstr);
		                    });
		                    next(list.join(''), page < pages);
                		}
			        }
			    }
            }
        });
    });
}

function loadDoorWarnData() {
	$('.door-msg-body-list.warnrecord>div:nth-child(1)').nextAll().remove();
	$('.door-msg-body-list.warnrecord').css('overflow-y', 'visible');
    layui.use('flow', function() {
        var $ = layui.jquery;
        var flow = layui.flow;
        flow.load({
            elem: '.door-msg-body-list.warnrecord',
            scrollElem: '.door-msg-body-list.warnrecord',
            done: function(page, next) {
                var list = [];
                Ajax('/room/alarm/list?pageSize=10&pageNum='+page+'&id='+roomid, loadDoorWarnDataBack);
			    function loadDoorWarnDataBack(result){
			        if (result.status == 200) {
			        	let data = result.result.data;
                		if (data != null && data != 'null') {
                			let total = result.result.total;
		                    let pages = Math.ceil(total/10);
		                    if (page > 1) {
		                        $('.door-msg-body-list.warnrecord').css('overflow-y', 'scroll');
		                    }
		                    layui.each(data, function(index, item) {
		                    	let divstr = `
		                    	    <div>
		                                <div style="flex:1">${item.deviceName}</div>
		                                <div style="flex:2">${item.eventTime}</div>
		                                <div style="flex:1">${item.eventStatus}</div>
		                            </div>
		                    	`;
		                        list.push(divstr);
		                    });
		                    next(list.join(''), page < pages);
                		}
			        }
			    }
            }
        });
    });
}

function loadDoorStatusData() {
	$('.door-msg-body-list.statusrecord>div:nth-child(1)').nextAll().remove();
	$('.door-msg-body-list.statusrecord').css('overflow-y', 'visible');
    layui.use('flow', function() {
        var $ = layui.jquery;
        var flow = layui.flow;
        flow.load({
            elem: '.door-msg-body-list.statusrecord',
            scrollElem: '.door-msg-body-list.statusrecord',
            done: function(page, next) {
                var list = [];
                Ajax('/room/lock/list?pageSize=10&pageNum='+page+'&id='+roomid, loadDoorStatusDataBack);
			    function loadDoorStatusDataBack(result){
			        if (result.status == 200) {
			        	let data = result.result.data;
                		if (data != null && data != 'null') {
                			let total = result.result.total;
		                    let pages = Math.ceil(total/10);
		                    if (page > 1) {
		                        $('.door-msg-body-list.statusrecord').css('overflow-y', 'scroll');
		                    }
		                    layui.each(data, function(index, item) {
		                    	let divstr = `
		                    	    <div>
		                                <div style="flex:1">${item.name}</div>
		                                <div style="flex:2">${item.batSigUpdateTime}</div>
		                                <div style="flex:1">${item.lockStatus}</div>
		                            </div>
		                    	`;
		                        list.push(divstr);
		                    });
		                    next(list.join(''), page < pages);
                		}
			        }
			    }
            }
        });
    });
}

function loadDoorRemoteData() {
	$('.door-msg-body-list.remoterecord>div:nth-child(1)').nextAll().remove();
	$('.door-msg-body-list.remoterecord').css('overflow-y', 'visible');
    layui.use('flow', function() {
        var $ = layui.jquery;
        var flow = layui.flow;
        flow.load({
            elem: '.door-msg-body-list.remoterecord',
            scrollElem: '.door-msg-body-list.remoterecord',
            done: function(page, next) {
                var list = [];
                Ajax('/room/remote/list?pageSize=10&pageNum='+page+'&id='+roomid, loadDoorRemoteDataBack);
			    function loadDoorRemoteDataBack(result){
			        if (result.status == 200) {
			        	let data = result.result.data;
                		if (data != null && data != 'null') {
                			let total = result.result.total;
		                    let pages = Math.ceil(total/10);
		                    if (page > 1) {
		                        $('.door-msg-body-list.remoterecord').css('overflow-y', 'scroll');
		                    }
		                    layui.each(data, function(index, item) {
		                    	let info = item.resultInfo;
		                    	if (info == '操作成功') {
		                    		info = '操作成功';
		                    	} else {
		                    		info = '操作失败';
		                    	}
		                    	let divstr = `
		                    	    <div>
		                                <div style="flex:1">${item.userName}</div>
		                                <div style="flex:2">${item.time}</div>
		                                <div style="flex:1" title="${item.resultInfo}">${info}</div>
		                            </div>
		                    	`;
		                        list.push(divstr);
		                    });
		                    next(list.join(''), page < pages);
                		}
			        }
			    }
            }
        });
    });
}
